<template>
  <div class="my-counter">
    <button type="button" class="btn btn-light" @click="delbtn">-</button>
    <input type="number" class="form-control inp" v-model="num" />
    <button type="button" class="btn btn-light" @click="addbtn">+</button>
  </div>
</template>

<script>
export default {
  props: ['item', 'sum'],

  data() {
    return {
      num: this.sum,
    }
  },
  methods: {
    addbtn() {
      this.$emit('addbtn', this.num++)
    },
    delbtn() {
      if (this.sum <= 0) return
      this.$emit('delbtn', this.num--)
    },
  },
}
</script>

<style lang="less" scoped>
.my-counter {
  display: flex;
  .inp {
    width: 60px;
    text-align: center;
    margin: 0 10px;
  }
  .btn,
  .inp {
    transform: scale(0.9);
  }
}
</style>
